﻿using Approval.Domain;
using Approval.Infrastructure.Interface;
using Approval.ReadAPI.Appliaction.Command.AcceptanceRelationCommand;
using MediatR;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PublicCommon;

namespace Approval.ReadAPI.Appliaction.CommandHandler.AcceptanceRelationCommandHandler
{
    public class AcceptanceRelationListCommandHandler : IRequestHandler<AcceptanceRelationListCommand, List<AcceptanceRelation>>
    {
        private readonly IAcceptanceRelationRepository acceptanceRelationRepository;

        public AcceptanceRelationListCommandHandler(IAcceptanceRelationRepository acceptanceRelationRepository)
        {
            this.acceptanceRelationRepository = acceptanceRelationRepository;
        }

        public async Task<List<AcceptanceRelation>> Handle(AcceptanceRelationListCommand request, CancellationToken cancellationToken)
        {
            var res = await acceptanceRelationRepository.GetListInfo(x => x.AId.Equals(request.AId));
            var list = res.OrderByDescending(x => x.Id);
            return list.ToList();
        }
    }
}
